﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaInfrastructure;

namespace GWApplication
{

    /// <summary>
    /// 概念化的模型
    /// </summary>
    [Serializable]
    public abstract class ConceptualModel:FEntity
    {
        public ConceptualModel(string id):base(id)
        {


         



 
        }


        [field:NonSerialized]
        public event EventHandler LayerAdded;


        [field:NonSerialized]
        public event EventHandler LayerRemoved;





        //保存所有的layer,具体设计有待考量

        List<TLayer> _layers = new List<TLayer>();

        public List<TLayer> Layers
        {
            get { return _layers; }
           
        }

        Dictionary<string, TLayer> _layersLookup = new Dictionary<string, TLayer>();




        public TLayer GetLayer(string id)
        {
            if (this._layersLookup.ContainsKey(id))
            {
                return this._layersLookup[id];
                

            }

            return null;

        }


        public void AddLayer(TLayer layer)
        {
            if (!this._layersLookup.ContainsKey(layer.Id))
            {
                this._layers.Add(layer);

                this._layersLookup.Add(layer.Id,layer);


                if (LayerAdded!=null)
                {
                    this.LayerAdded(layer, EventArgs.Empty);
                    
                }

            }

            
 
        }


        public void RemoveLayer(string id)
        {

            if (this._layersLookup.ContainsKey(id))
            {
                TLayer layer = this._layersLookup[id];

                this._layers.Remove(layer);

                this._layersLookup.Remove(layer.Id);

                if (LayerRemoved!=null)
                {
                    LayerRemoved(layer,EventArgs.Empty);
                    
                }

            }
 

        }








    }



}
